package com.gxa.jjty.phy.controller;

import com.gxa.jjty.core.common.JsonResult;
import com.gxa.jjty.core.exception.BusinessException;
import com.gxa.jjty.core.pojo.ServerAndTorderVo;
import com.gxa.jjty.core.pojo.Torder;
import com.gxa.jjty.phy.service.ServerAndToderVoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "订单查询视图的接口")
@RestController
@RequestMapping("/voSelect")
public class ServerAndToderVoController {

    @Autowired
    private ServerAndToderVoService serverAndToderVoService;

    @ApiOperation("根据订单号/姓名/服务 来查询的方法")
    @PostMapping("/select")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "search",value = "搜索内容"),
            @ApiImplicitParam(name = "orderState",value = "订单状态"),
            @ApiImplicitParam(name = "phyId",value = "陪护员id")
    })
    public Map select(String search, Integer orderState, Long phyId) throws BusinessException {
        List<ServerAndTorderVo> serverAndTorderVos = serverAndToderVoService.selectByNameOrServer(search, orderState, phyId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(serverAndTorderVos);
        return  jsonResult.getDataMap();
    }

    @ApiOperation("获取各类订单的总方法")
    @PostMapping("/selectTorder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phyId",value = "陪护员id"),
            @ApiImplicitParam(name = "orderState",value = "订单状态")
    })
    public Map selectTorder(Long phyId,Integer orderState) throws IllegalAccessException {
        List<ServerAndTorderVo> select = null;
        if(orderState==1){
            ServerAndTorderVo serverAndTorderVo = new ServerAndTorderVo();
            serverAndTorderVo.setOrderState("等待系统分配");
             select = serverAndToderVoService.select(serverAndTorderVo);
            ServerAndTorderVo serverAndTorderVo1 = new ServerAndTorderVo();
            serverAndTorderVo1.setTransferPhyId("/"+phyId.toString()+"/");
            List<ServerAndTorderVo> select1 = serverAndToderVoService.selectDescLike(serverAndTorderVo1);
            for(int i=0;i<select1.size();i++){
                select.add(select1.get(i));
            }
        }else if(orderState==2){
            ServerAndTorderVo serverAndTorderVo = new ServerAndTorderVo();
            serverAndTorderVo.setPhyId(phyId);
            serverAndTorderVo.setOrderState("陪护员已接单");
            select = serverAndToderVoService.select(serverAndTorderVo);
        }else if(orderState==3){
            ServerAndTorderVo serverAndTorderVo = new ServerAndTorderVo();
            serverAndTorderVo.setPhyId(phyId);
            serverAndTorderVo.setOrderState("服务中");
            select = serverAndToderVoService.select(serverAndTorderVo);
        }else if(orderState==4){
            ServerAndTorderVo serverAndTorderVo = new ServerAndTorderVo();
            serverAndTorderVo.setPhyId(phyId);
            serverAndTorderVo.setOrderState("已完成");
            select =serverAndToderVoService.select2(serverAndTorderVo);
        }else if(orderState==5){
            ServerAndTorderVo serverAndTorderVo = new ServerAndTorderVo();
            serverAndTorderVo.setPhyId(phyId);
            serverAndTorderVo.setOrderState("已取消");
            select = serverAndToderVoService.select(serverAndTorderVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(select);
        return  jsonResult.getDataMap();
    }


}
